package com.bwie.goods.service.impl;

import com.bwie.common.domain.Vehicle;
import com.bwie.common.result.Result;
import com.bwie.goods.mapper.VehicleMapper;
import com.bwie.goods.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

import static jdk.nashorn.internal.objects.NativeArray.lastIndexOf;

@Service
public class VehicleServiceimpl implements VehicleService {
    @Autowired
    VehicleMapper vehicleMapper;

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public Result<List<Vehicle>> list() {
        List<Vehicle> vehiclelist=vehicleMapper.list();
        for (Vehicle vehicle : vehiclelist) {
            redisTemplate.opsForList().range("vehicle",0,-1);
        }
        return Result.success(vehiclelist);
    }

    @Override
    public Result vehicleAdd(Vehicle vehicle) {
        Integer i=vehicleMapper.vehicleAdd(vehicle);


        return Result.success(i>0,i>0?"添加成功":"添加失败");
    }

    @Override
    public Result del(Integer id) {
        Integer i=vehicleMapper.del(id);
        return Result.success(i>0,i>0?"删除成功":"删除失败");
    }

    @Override
    public Result<Vehicle> update(Integer id) {
        Vehicle vehicle=vehicleMapper.update(id);
        return Result.success(vehicle);
    }
}
